<!DOCTYPE html>
<html lang="en" class="js csstransforms3d">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="generator" content="Hugo 0.20.7" />
    <meta name="description" content="">


    <link rel="shortcut icon" href="http://shardingjdbc.io/document/legacy/2.x/en/img/favicon.png" type="image/x-icon" />

    
    <title>Orchestration</title>
    <link href="http://ovfotjrsi.bkt.clouddn.com/docs/css/nucleus.css" rel="stylesheet">
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="http://ovfotjrsi.bkt.clouddn.com/docs/css/theme.css" rel="stylesheet">
    <link href="http://ovfotjrsi.bkt.clouddn.com/docs/css/hugo-theme.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <style type="text/css">:root #header + #content > #left > #rlblock_left
    {display:none !important;}</style>
    <link rel="stylesheet" href="http://cdn.bootcss.com/highlight.js/9.8.0/styles/monokai-sublime.min.css">
<link rel="stylesheet" href="http://ovfotjrsi.bkt.clouddn.com/docs/css/style.css">
  </head>
  <body class="" data-url="/02-guide/orchestration/">
    
    <nav id="sidebar">
  <div id="header-wrapper">
    <div id="header">
      <img src="http://ovfotjrsi.bkt.clouddn.com/docs/img/sharding-jdbc.png" />
    </div>
</div>
  <div class="highlightable">
    <ul class="topics">
      
        
        
          
          
            
          
        
          
          
            
          
        
          
          
            
          
        
          
          
            
          
        
        
        
          
        
          
        
          
        
          
        
      
      
      
      

      
      
      
        
          
          
            
          
        
      
      
      

      <li class="dd-item  " data-nav-id="/00-overview/">
        <a href="http://shardingjdbc.io/document/legacy/2.x/en/00-overview/">
          <span>
            
              <b>0. </b>
            
             Overview
            
           </span>
        </a>
        
        <ul>
          
            <li class="dd-item " data-nav-id="/00-overview/intro/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/00-overview/intro/">
                <span>Brief Introduction     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/00-overview/news/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/00-overview/news/">
                <span>News     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/00-overview/contribution/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/00-overview/contribution/">
                <span>Contribute Code     </i></span>
              </a>
            </li>
          
        </ul>
        
      </li>
      
      
      

      
      
      
        
          
          
            
          
        
      
      
      

      <li class="dd-item  " data-nav-id="/01-start/">
        <a href="http://shardingjdbc.io/document/legacy/2.x/en/01-start/">
          <span>
            
              <b>1. </b>
            
             Introduction
            
           </span>
        </a>
        
        <ul>
          
            <li class="dd-item " data-nav-id="/01-start/quick-start/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/01-start/quick-start/">
                <span>Quick Start     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/01-start/code-demo/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/01-start/code-demo/">
                <span>Usage Example     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/01-start/faq/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/01-start/faq/">
                <span>FAQ     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/01-start/features/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/01-start/features/">
                <span>Feature List     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/01-start/limitations/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/01-start/limitations/">
                <span>Use Limits     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/01-start/sql-supported/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/01-start/sql-supported/">
                <span>The list of available SQL syntax     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/01-start/stress-test/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/01-start/stress-test/">
                <span>The performance-test report     </i></span>
              </a>
            </li>
          
        </ul>
        
      </li>
      
      
      

      
      
      
        
          
          
            
          
        
      
      
      

      <li class="dd-item  parent" data-nav-id="/02-guide/">
        <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/">
          <span>
            
              <b>2. </b>
            
             User Manual
            
           </span>
        </a>
        
        <ul>
          
            <li class="dd-item " data-nav-id="/02-guide/concepts/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/concepts/">
                <span>Basic Concepts      </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/sharding/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/sharding/">
                <span>Sharding     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/master-slave/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/master-slave/">
                <span>Read-write splitting     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/config_domain/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/config_domain/">
                <span>Domain Model Configuration     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/configuration/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/configuration/">
                <span>Configuration     </i></span>
              </a>
            </li>
          
            <li class="dd-item active" data-nav-id="/02-guide/orchestration/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/orchestration/">
                <span>Orchestration     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/hint-sharding-value/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/hint-sharding-value/">
                <span>Mandatory Routing     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/key-generator/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/key-generator/">
                <span>Distributed Primary key     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/transaction/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/transaction/">
                <span>Transaction Support     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/subquery/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/subquery/">
                <span>The Pagination and subquery     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/test-framework/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/test-framework/">
                <span>Test Engine     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/apm/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/apm/">
                <span>APM     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/sharding-jdbc-server/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/sharding-jdbc-server/">
                <span>Sharding-JDBC-Server     </i></span>
              </a>
            </li>
          
        </ul>
        
      </li>
      
      
      

      
      
      
        
          
          
            
          
        
      
      
      

      <li class="dd-item  " data-nav-id="/03-design/">
        <a href="http://shardingjdbc.io/document/legacy/2.x/en/03-design/">
          <span>
            
              <b>3. </b>
            
             Design Plan
            
           </span>
        </a>
        
        <ul>
          
            <li class="dd-item " data-nav-id="/03-design/architecture/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/03-design/architecture/">
                <span>Architecture Design     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/03-design/module/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/03-design/module/">
                <span>Module Declaration     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/03-design/roadmap/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/en/03-design/roadmap/">
                <span>Roadmap     </i></span>
              </a>
            </li>
          
        </ul>
        
      </li>
      
      
    </ul>
    <hr>
     
  </div>
</nav>

        <section id="body">
        <div id="overlay"></div>

        <div class="padding highlightable">

            <div id="top-bar">
              
              <div id="breadcrumbs" itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb">
                  <span id="sidebar-toggle-span">
                      <a href="#" id="sidebar-toggle" data-sidebar-toggle="">
                        <i class="fa fa-bars"></i>
                      </a>
                  </span>
                
                <span id="toc-menu"><a href=""><i class="fa fa-list-alt"></i></a></span>
                
                
                  
                  
                  
                    
                    
                <a href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/" itemprop="url"><span itemprop="title">User Manual</span></a> <i class="fa fa-angle-right"></i>
                    
                  
                
                <span itemprop="title"> Orchestration</span>
              </div>
              
                  <div class="progress">
    <div class="wrapper">
<nav id="TableOfContents">
<ul>
<li>
<ul>
<li><a href="#zookeeper">Zookeeper</a></li>
<li><a href="#etcd">Etcd</a></li>
<li><a href="#the-structure-of-registry">The structure of registry</a></li>
<li><a href="#the-config-node">The config node</a>
<ul>
<li><a href="#the-child-node-of-data-source">The child node of data source</a></li>
<li><a href="#the-child-node-of-sharding">The child node of sharding</a>
<ul>
<li><a href="#the-child-node-of-rule">The child node of rule</a></li>
<li><a href="#the-child-node-of-configmap">The child node of ConfigMap</a></li>
<li><a href="#the-child-node-of-props">The child node of props</a></li>
</ul></li>
<li><a href="#the-child-node-of-master-slave">The child node of Master-Slave</a>
<ul>
<li><a href="#the-child-node-of-rule-1">The child node of rule</a></li>
<li><a href="#the-child-of-configmap">The child of ConfigMap</a></li>
</ul></li>
</ul></li>
<li><a href="#the-state-node">The state node</a>
<ul>
<li><a href="#the-instance-node">The instance node</a></li>
<li><a href="#the-data-source-node">The data source node</a></li>
</ul></li>
</ul></li>
<li><a href="#operation-guide">Operation guide</a>
<ul>
<li><a href="#the-instance-node-1">The instance node</a></li>
<li><a href="#the-data-source-node-1">The data source node</a></li>
</ul></li>
<li><a href="#operation-examples">Operation examples</a>
<ul>
<li><a href="#1-the-java-configuration">1. The JAVA configuration</a>
<ul>
<li><a href="#import-the-dependency-of-maven">Import the dependency of maven</a></li>
<li><a href="#the-config-example-of-zookeeper">The config example of Zookeeper</a></li>
<li><a href="#the-config-example-of-etcd">The config example of Etcd</a></li>
</ul></li>
<li><a href="#2-the-yaml-configuration">2. The YAML configuration</a>
<ul>
<li><a href="#import-the-dependency-of-maven-1">Import the dependency of maven</a></li>
<li><a href="#th-configuration-examples">Th Configuration examples</a>
<ul>
<li><a href="#the-introduction-for-orchestration-configs-of-sharding-in-zookeeper">The introduction for orchestration configs of Sharding in Zookeeper</a></li>
<li><a href="#the-introduction-for-orchestration-configs-of-sharding-in-etcd">The introduction for orchestration configs of Sharding in Etcd</a>
<ul>
<li><a href="#the-introduction-for-orchestration-configs-of-read-write-splitting-in-zookeeper">The introduction for orchestration configs of Read-write splitting in Zookeeper</a></li>
<li><a href="#the-introduction-for-orchestration-configs-of-read-write-splitting-in-etcd">The introduction for orchestration configs of Read-write splitting in Etcd</a></li>
<li><a href="#sharding-datasource-creation">Sharding DataSource Creation</a></li>
<li><a href="#read-write-splitting-datasource-creation">Read-write splitting DataSource Creation</a></li>
</ul></li>
</ul></li>
<li><a href="#more-detail-on-yaml-configuration">More detail on YAML Configuration</a></li>
</ul></li>
<li><a href="#3-the-spring-namespace-configuration">3. The Spring namespace configuration</a>
<ul>
<li><a href="#import-the-dependency-of-maven-2">Import the dependency of maven</a></li>
<li><a href="#the-configuration-example-in-zookeeper">The configuration example in Zookeeper</a></li>
<li><a href="#the-introduction-for-labels-in-zookeeper">The introduction for labels in Zookeeper</a>
<ul>
<li><a href="#reg-zookeeper">&lt;reg:zookeeper/&gt;</a></li>
</ul></li>
<li><a href="#the-config-example-in-etcd">The config example in Etcd</a></li>
<li><a href="#the-introduction-for-labels-in-etcd">The introduction for labels in Etcd</a>
<ul>
<li><a href="#reg-etcd">&lt;reg:etcd/&gt;</a></li>
</ul></li>
</ul></li>
<li><a href="#4-the-spring-boot-configuration">4. The Spring Boot Configuration</a>
<ul>
<li><a href="#import-the-dependency-of-maven-3">Import the dependency of maven</a></li>
<li><a href="#the-configuration-example-in-zookeeper-1">The configuration example in Zookeeper</a>
<ul>
<li><a href="#the-introduction-for-orchestration-configs-of-sharding-in-spring-boot">The introduction for orchestration configs of Sharding in Spring Boot</a></li>
</ul></li>
<li><a href="#the-configuration-example-in-etcd">The configuration example in Etcd</a>
<ul>
<li><a href="#the-introduction-for-orchestration-configs-of-read-write-splitting-in-spring-boot">The introduction for orchestration configs of Read-write splitting in Spring Boot</a></li>
<li><a href="#the-introduction-for-orchestration-configs-of-sharding-in-spring-boot-1">The introduction for orchestration configs of Sharding in Spring Boot</a></li>
</ul></li>
</ul></li>
</ul></li>
</ul>
</nav>
    </div>
</div>

              

            </div>
            
              <div id="body-inner">
                
                <h1>Orchestration</h1>
                



<p>Sharding-JDBC provides orchestration for databases in Version 2.0.0.M1, which mainly includes:</p>

<ul>
<li>The centralized and dynamic configuration can support the dynamic strategy switching of Sharding and read-write splitting.</li>
<li>Provide the circuit-breaker mechanism for database access, and the switch that disables access to Slaves.</li>
<li>Support for Zookeeper and Etcd registry.</li>
</ul>

<h2 id="zookeeper">Zookeeper</h2>

<p>Please use Zookeeper 3.4.6 and above to set up the registration center. <a href="https://zookeeper.apache.org/doc/trunk/zookeeperStarted.html">Reference</a></p>

<h2 id="etcd">Etcd</h2>

<p>Please use Etcd V3 and above to set up the registration center. <a href="https://coreos.com/etcd/docs/latest">Reference</a></p>

<h2 id="the-structure-of-registry">The structure of registry</h2>

<p>The registry is defined in the namespace and you can create the object running node to access the database, by which you can distinguish different accessing instances. The namespace contains two child nodes, namely, config and state.</p>

<h2 id="the-config-node">The config node</h2>

<p>It mainly includes the data-management related configuration information such as data source, Sharding, Read-write splitting, ConfigMap and configuration of the Properties, stored in a JSON format. You can modify this node to get dynamic configuration management.</p>

<pre><code>config
    ├──datasource                                # The config of data source 
    ├──sharding                                  # The root node of Sharding configuration
    ├      ├──rule                               # The rule of Sharding
    ├      ├──configmap                          # The ConfigMap config of Sharding, stored in the form of K/V, e.g. {&quot;key1&quot;:&quot;value1&quot;}
    ├      ├──props                              # The config of Properties
    ├──masterslave                               # The config of Read-write splitting
    ├      ├──rule                               # The rule of Read-write splitting 
    ├      ├──configmap                          # The ConfigMap config of Read-write splitting, stored in the form of K/V, e.g. {&quot;key1&quot;:&quot;value1&quot;}
</code></pre>

<h3 id="the-child-node-of-data-source">The child node of data source</h3>

<p>It is a collection of multiple database connection pools, and the properties of different connection pools should be configured by users, e.g. DBCP，C3P0，Druid, HikariCP.</p>

<pre><code class="language-json">[{&quot;name&quot;:&quot;demo_ds&quot;,&quot;clazz&quot;:&quot;org.apache.commons.dbcp.BasicDataSource&quot;,&quot;defaultAutoCommit&quot;:&quot;true&quot;,&quot;defaultReadOnly&quot;:&quot;false&quot;,&quot;defaultTransactionIsolation&quot;:&quot;-1&quot;,&quot;driverClassName&quot;:&quot;com.mysql.jdbc.Driver&quot;,&quot;initialSize&quot;:&quot;0&quot;,&quot;logAbandoned&quot;:&quot;false&quot;,&quot;maxActive&quot;:&quot;8&quot;,&quot;maxIdle&quot;:&quot;8&quot;,&quot;maxOpenPreparedStatements&quot;:&quot;-1&quot;,&quot;maxWait&quot;:&quot;-1&quot;,&quot;minEvictableIdleTimeMillis&quot;:&quot;1800000&quot;,&quot;minIdle&quot;:&quot;0&quot;,&quot;numTestsPerEvictionRun&quot;:&quot;3&quot;,&quot;password&quot;:&quot;&quot;,&quot;removeAbandoned&quot;:&quot;false&quot;,&quot;removeAbandonedTimeout&quot;:&quot;300&quot;,&quot;testOnBorrow&quot;:&quot;false&quot;,&quot;testOnReturn&quot;:&quot;false&quot;,&quot;testWhileIdle&quot;:&quot;false&quot;,&quot;timeBetweenEvictionRunsMillis&quot;:&quot;-1&quot;,&quot;url&quot;:&quot;jdbc:mysql://localhost:3306/demo_ds&quot;,&quot;username&quot;:&quot;root&quot;,&quot;validationQueryTimeout&quot;:&quot;-1&quot;}]
</code></pre>

<h3 id="the-child-node-of-sharding">The child node of sharding</h3>

<h4 id="the-child-node-of-rule">The child node of rule</h4>

<p>The configuration of Sharding, including the configs of  Sharding and Read-write splitting.</p>

<pre><code class="language-json">{&quot;tableRuleConfigs&quot;:[{&quot;logicTable&quot;:&quot;t_order&quot;,&quot;actualDataNodes&quot;:&quot;demo_ds.t_order_${0..1}&quot;,&quot;databaseShardingStrategyConfig&quot;:{},&quot;tableShardingStrategyConfig&quot;:{&quot;type&quot;:&quot;STANDARD&quot;,&quot;shardingColumn&quot;:&quot;order_id&quot;,&quot;preciseAlgorithmClassName&quot;:&quot;io.shardingjdbc.example.orchestration.spring.namespace.mybatis.algorithm.PreciseModuloTableShardingAlgorithm&quot;,&quot;rangeAlgorithmClassName&quot;:&quot;&quot;},&quot;keyGeneratorColumnName&quot;:&quot;order_id&quot;},{&quot;logicTable&quot;:&quot;t_order_item&quot;,&quot;actualDataNodes&quot;:&quot;demo_ds.t_order_item_${0..1}&quot;,&quot;databaseShardingStrategyConfig&quot;:{},&quot;tableShardingStrategyConfig&quot;:{&quot;type&quot;:&quot;STANDARD&quot;,&quot;shardingColumn&quot;:&quot;order_id&quot;,&quot;preciseAlgorithmClassName&quot;:&quot;io.shardingjdbc.example.orchestration.spring.namespace.mybatis.algorithm.PreciseModuloTableShardingAlgorithm&quot;,&quot;rangeAlgorithmClassName&quot;:&quot;&quot;},&quot;keyGeneratorColumnName&quot;:&quot;order_item_id&quot;}],&quot;bindingTableGroups&quot;:[&quot;t_order, t_order_item&quot;],&quot;defaultDatabaseShardingStrategyConfig&quot;:{},&quot;defaultTableShardingStrategyConfig&quot;:{},&quot;masterSlaveRuleConfigs&quot;:[]}
</code></pre>

<h4 id="the-child-node-of-configmap">The child node of ConfigMap</h4>

<p>The ConfigMap config of Sharding, stored in the form of K/V.</p>

<pre><code class="language-json">{&quot;key1&quot;:&quot;value1&quot;}
</code></pre>

<h4 id="the-child-node-of-props">The child node of props</h4>

<p>They are the Sharding Properties in sharding-jdbc configuration.</p>

<pre><code class="language-json">{&quot;executor.size&quot;:&quot;20&quot;,&quot;sql.show&quot;:&quot;true&quot;}
</code></pre>

<h3 id="the-child-node-of-master-slave">The child node of Master-Slave</h3>

<h4 id="the-child-node-of-rule-1">The child node of rule</h4>

<p>The configuration for using Read-write splitting alone.</p>

<pre><code class="language-json">{&quot;name&quot;:&quot;ds_ms&quot;,&quot;masterDataSourceName&quot;:&quot;ds_master&quot;,&quot;slaveDataSourceNames&quot;:[&quot;ds_slave_0&quot;,&quot;ds_slave_1&quot;],&quot;loadBalanceAlgorithmType&quot;:&quot;ROUND_ROBIN&quot;}
</code></pre>

<h4 id="the-child-of-configmap">The child of ConfigMap</h4>

<p>The ConfigMap config of Sharding, stored in the form of K/V.</p>

<pre><code class="language-json">{&quot;key1&quot;:&quot;value1&quot;}
</code></pre>

<h2 id="the-state-node">The state node</h2>

<p>It contains the nodes of instance and data source.</p>

<pre><code>instances
    ├──your_instance_ip_a@-@your_instance_pid_x
    ├──your_instance_ip_b@-@your_instance_pid_y
    ├──....                                    
</code></pre>

<h3 id="the-instance-node">The instance node</h3>

<p>It includes the running-instance information of database-accessing object, and its child node is the identity of the current running instance. This identify is composed of IP and PID in the running server and always a temporary node. It is registered when the instance is online, and automatically cleaned when the instance is offline. The registry manages the access to the database by monitoring changes in these nodes.</p>

<h3 id="the-data-source-node">The data source node</h3>

<p>It is used to manage Read-write splitting and dynamically add, remove or disable data sources (Expected in 2.0.0.M3 release).</p>

<h1 id="operation-guide">Operation guide</h1>

<h2 id="the-instance-node-1">The instance node</h2>

<p>You can write DISABLED (case ignored) to the IP address @-@pid node to disable the instance or remove DISABLED to enable.</p>

<p>The commands in Zookeeper:</p>

<pre><code>[zk: localhost:2181(CONNECTED) 0] set /your_zk_namespace/your_app_name/state/instances/your_instance_ip_a@-@your_instance_pid_x DISABLED
</code></pre>

<p>The commands in Etcd:</p>

<pre><code>etcdctl set /your_app_name/state/instances/your_instance_ip_a@-@your_instance_pid_x DISABLED
</code></pre>

<h2 id="the-data-source-node-1">The data source node</h2>

<p>In use of Read-write splitting or Sharding + Read-write splitting, you can write DISABLED to the child node in data source to disable slaves or remove DISABLED to enable (Expected in 2.0.0.M3 release).</p>

<p>The commands in Zookeeper:</p>

<pre><code>[zk: localhost:2181(CONNECTED) 0] set /your_zk_namespace/your_app_name/state/datasources/your_slave_datasource_name DISABLED
</code></pre>

<p>The commands in Etcd:</p>

<pre><code>etcdctl set /your_app_name/state/datasources/your_slave_datasource_name DISABLED
</code></pre>

<h1 id="operation-examples">Operation examples</h1>

<h2 id="1-the-java-configuration">1. The JAVA configuration</h2>

<h3 id="import-the-dependency-of-maven">Import the dependency of maven</h3>

<pre><code class="language-xml">&lt;dependency&gt;
    &lt;groupId&gt;io.shardingjdbc&lt;/groupId&gt;
    &lt;artifactId&gt;sharding-jdbc-orchestration&lt;/artifactId&gt;
    &lt;version&gt;${latest.release.version}&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>

<h3 id="the-config-example-of-zookeeper">The config example of Zookeeper</h3>

<pre><code class="language-java">    DataSource dataSource = OrchestrationShardingDataSourceFactory.createDataSource(
                 createDataSourceMap(), createShardingRuleConfig(), new ConcurrentHashMap&lt;String, Object&gt;(), new Properties(), 
                     new OrchestrationConfiguration(&quot;orchestration-sharding-data-source&quot;, getRegistryCenterConfiguration(), false));
     
    private static RegistryCenterConfiguration getRegistryCenterConfiguration() {
        ZookeeperConfiguration result = new ZookeeperConfiguration();
        result.setServerLists(&quot;localhost:2181&quot;);
        result.setNamespace(&quot;orchestration-demo&quot;);
        return result;
    }
</code></pre>

<h3 id="the-config-example-of-etcd">The config example of Etcd</h3>

<pre><code class="language-java">    DataSource dataSource = OrchestrationShardingDataSourceFactory.createDataSource(
                 createDataSourceMap(), createShardingRuleConfig(), new ConcurrentHashMap&lt;String, Object&gt;(), new Properties(), 
                 new OrchestrationConfiguration(&quot;orchestration-sharding-data-source&quot;, getRegistryCenterConfiguration(), false));
    
    private static RegistryCenterConfiguration getRegistryCenterConfiguration() {
        EtcdConfiguration result = new EtcdConfiguration();
        result.setServerLists(&quot;http://localhost:2379&quot;);
        return result;
    }
</code></pre>

<h2 id="2-the-yaml-configuration">2. The YAML configuration</h2>

<h3 id="import-the-dependency-of-maven-1">Import the dependency of maven</h3>

<pre><code class="language-xml">&lt;dependency&gt;
    &lt;groupId&gt;io.shardingjdbc&lt;/groupId&gt;
    &lt;artifactId&gt;sharding-jdbc-core&lt;/artifactId&gt;
    &lt;version&gt;${latest.release.version}&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>

<h3 id="th-configuration-examples">Th Configuration examples</h3>

<h4 id="the-introduction-for-orchestration-configs-of-sharding-in-zookeeper">The introduction for orchestration configs of Sharding in Zookeeper</h4>

<pre><code class="language-yaml">dataSources:
  db0: !!org.apache.commons.dbcp.BasicDataSource
    driverClassName: org.h2.Driver
    url: jdbc:h2:mem:db0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
    username: sa
    password: 
    maxActive: 100
  db1: !!org.apache.commons.dbcp.BasicDataSource
    driverClassName: org.h2.Driver
    url: jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
    username: sa
    password: 
    maxActive: 100

shardingRule:
  tables:
    config:
      actualDataNodes: db${0..1}.t_config
    t_order: 
      actualDataNodes: db${0..1}.t_order_${0..1}
      databaseStrategy: 
        standard:
          shardingColumn: user_id
          preciseAlgorithmClassName: io.shardingjdbc.core.yaml.fixture.SingleAlgorithm
      tableStrategy: 
        inline:
          shardingColumn: order_id
          algorithmInlineExpression: t_order_${order_id % 2}
      keyGeneratorColumnName: order_id
      keyGeneratorClass: io.shardingjdbc.core.yaml.fixture.IncrementKeyGenerator
    t_order_item:
      actualDataNodes: db${0..1}.t_order_item_${0..1}
      #The strategies in other binding tables are same as the first binding table.
      databaseStrategy: 
        standard:
          shardingColumn: user_id
          preciseAlgorithmClassName: io.shardingjdbc.core.yaml.fixture.SingleAlgorithm
      tableStrategy: 
        inline:
          shardingColumn: order_id
          algorithmInlineExpression: t_order_item_${order_id % 2}
  bindingTables:
    - t_order,t_order_item
  #默认数据库分片策略
  defaultDatabaseStrategy:
    none:
  defaultTableStrategy:
    complex:
      shardingColumns: id, order_id
      algorithmClassName: io.shardingjdbc.core.yaml.fixture.MultiAlgorithm
  props:
    sql.show: true

orchestration:
  name: demo_yaml_ds_sharding_ms
  overwrite: true
  zookeeper:
    namespace: orchestration-yaml-demo
    serverLists: localhost:2181
</code></pre>

<h4 id="the-introduction-for-orchestration-configs-of-sharding-in-etcd">The introduction for orchestration configs of Sharding in Etcd</h4>

<pre><code class="language-yaml">dataSources:
  db0: !!org.apache.commons.dbcp.BasicDataSource
    driverClassName: org.h2.Driver
    url: jdbc:h2:mem:db0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
    username: sa
    password: 
    maxActive: 100
  db1: !!org.apache.commons.dbcp.BasicDataSource
    driverClassName: org.h2.Driver
    url: jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
    username: sa
    password: 
    maxActive: 100

shardingRule:
  tables:
    config:
      actualDataNodes: db${0..1}.t_config
    t_order: 
      actualDataNodes: db${0..1}.t_order_${0..1}
      databaseStrategy: 
        standard:
          shardingColumn: user_id
          preciseAlgorithmClassName: io.shardingjdbc.core.yaml.fixture.SingleAlgorithm
      tableStrategy: 
        inline:
          shardingColumn: order_id
          algorithmInlineExpression: t_order_${order_id % 2}
      keyGeneratorColumnName: order_id
      keyGeneratorClass: io.shardingjdbc.core.yaml.fixture.IncrementKeyGenerator
    t_order_item:
      actualDataNodes: db${0..1}.t_order_item_${0..1}
      databaseStrategy: 
        standard:
          shardingColumn: user_id
          preciseAlgorithmClassName: io.shardingjdbc.core.yaml.fixture.SingleAlgorithm
      tableStrategy: 
        inline:
          shardingColumn: order_id
          algorithmInlineExpression: t_order_item_${order_id % 2}
  bindingTables:
    - t_order,t_order_item
  # The default strategy of Sharding 
  defaultDatabaseStrategy:
    none:
  defaultTableStrategy:
    complex:
      shardingColumns: id, order_id
      algorithmClassName: io.shardingjdbc.core.yaml.fixture.MultiAlgorithm
  props:
    sql.show: true

orchestration:
  name: demo_yaml_ds_sharding_ms
  overwrite: true
  etcd:
    serverLists: http://localhost:2379
</code></pre>

<h5 id="the-introduction-for-orchestration-configs-of-read-write-splitting-in-zookeeper">The introduction for orchestration configs of Read-write splitting in Zookeeper</h5>

<pre><code class="language-yaml">dataSources: # The config of data source

shardingRule: # The config of Sharding rules

orchestration: The orchestration configs in Zookeeper
  name: # The node name of the orchestration service
  overwrite: # to decide whether the local configuration can override the registry configuration. If true, the config in each boot is based on the local configuration.
  zookeeper: # The config of registry in Zookeeper
    namespace: # The namespace in Zookeeper
    serverLists: # The server list to connect to Zookeeper, including IP and port, mulitple addresses separated by commas, e.g. host1:2181,host2:2181.
    baseSleepTimeMilliseconds: # The initial value of the interval for retry, unit: Millisecond.
    maxSleepTimeMilliseconds: # The max value of the interval for retry, unit: Millisecond.
    maxRetries: # The number of retry. 
    sessionTimeoutMilliseconds: # Session timeout, unit: Millisecond.
    connectionTimeoutMilliseconds: # Connection timeout, unit: Millisecond.
    digest: # The permission token to connect to Zookeeper, and the default is no permission validation.
</code></pre>

<h5 id="the-introduction-for-orchestration-configs-of-read-write-splitting-in-etcd">The introduction for orchestration configs of Read-write splitting in Etcd</h5>

<p>The configuration items are same as <a href="#The introduction for orchestration configs of Read-write splitting in Zookeeper">The introduction for orchestration configs of Read-write splitting in Zookeeper</a>.</p>

<pre><code class="language-yaml">dataSources: 

shardingRule:  

orchestration:  
  name:  
  overwrite:  
  etcd: 
    serverLists: 
    timeToLiveSeconds: 
    timeoutMilliseconds: 
    maxRetries: 
    retryIntervalMilliseconds: 
</code></pre>

<h5 id="sharding-datasource-creation">Sharding DataSource Creation</h5>

<pre><code class="language-java">    DataSource dataSource = OrchestrationShardingDataSourceFactory.createDataSource(yamlFile);
</code></pre>

<h5 id="read-write-splitting-datasource-creation">Read-write splitting DataSource Creation</h5>

<pre><code class="language-java">    DataSource dataSource = OrchestrationMasterSlaveDataSourceFactory.createDataSource(yamlFile);
</code></pre>

<h3 id="more-detail-on-yaml-configuration">More detail on YAML Configuration</h3>

<p>!! :implementation class.</p>

<p>[] :multiple items.</p>

<h2 id="3-the-spring-namespace-configuration">3. The Spring namespace configuration</h2>

<h3 id="import-the-dependency-of-maven-2">Import the dependency of maven</h3>

<pre><code class="language-xml">&lt;dependency&gt;
    &lt;groupId&gt;io.shardingjdbc&lt;/groupId&gt;
    &lt;artifactId&gt;sharding-jdbc-orchestration-spring-namespace&lt;/artifactId&gt;
    &lt;version&gt;${latest.release.version}&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>

<h3 id="the-configuration-example-in-zookeeper">The configuration example in Zookeeper</h3>

<pre><code class="language-xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
    xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
    xmlns:sharding=&quot;http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding&quot;
    xmlns:reg=&quot;http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg&quot;
    xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/context 
                        http://www.springframework.org/schema/context/spring-context.xsd 
                        http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding 
                        http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding/sharding.xsd 
                        http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg 
                        http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg/reg.xsd
                        &quot;&gt;
    &lt;context:property-placeholder location=&quot;classpath:conf/rdb/conf.properties&quot; ignore-unresolvable=&quot;true&quot; /&gt;
    
    &lt;bean id=&quot;dbtbl_0&quot; class=&quot;org.apache.commons.dbcp.BasicDataSource&quot; destroy-method=&quot;close&quot;&gt;
        &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot; /&gt;
        &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost:3306/dbtbl_0&quot; /&gt;
        &lt;property name=&quot;username&quot; value=&quot;root&quot; /&gt;
        &lt;property name=&quot;password&quot; value=&quot;&quot; /&gt;
    &lt;/bean&gt;
    
    &lt;bean id=&quot;dbtbl_1&quot; class=&quot;org.apache.commons.dbcp.BasicDataSource&quot; destroy-method=&quot;close&quot;&gt;
        &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot; /&gt;
        &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost:3306/dbtbl_1&quot; /&gt;
        &lt;property name=&quot;username&quot; value=&quot;root&quot; /&gt;
        &lt;property name=&quot;password&quot; value=&quot;&quot; /&gt;
    &lt;/bean&gt;
    
    &lt;sharding:standard-strategy id=&quot;databaseStrategy&quot; sharding-column=&quot;user_id&quot; precise-algorithm-class=&quot;io.shardingjdbc.spring.algorithm.PreciseModuloDatabaseShardingAlgorithm&quot; /&gt;
    &lt;sharding:standard-strategy id=&quot;tableStrategy&quot; sharding-column=&quot;order_id&quot; precise-algorithm-class=&quot;io.shardingjdbc.spring.algorithm.PreciseModuloTableShardingAlgorithm&quot; /&gt;
    
    &lt;sharding:data-source id=&quot;shardingDataSource&quot; registry-center-ref=&quot;regCenter&quot;&gt;
        &lt;sharding:sharding-rule data-source-names=&quot;dbtbl_0,dbtbl_1&quot; default-data-source-name=&quot;dbtbl_0&quot;&gt;
            &lt;sharding:table-rules&gt;
                &lt;sharding:table-rule logic-table=&quot;t_order&quot; actual-data-nodes=&quot;dbtbl_${0..1}.t_order_${0..3}&quot; database-strategy-ref=&quot;databaseStrategy&quot; table-strategy-ref=&quot;tableStrategy&quot; /&gt;
                &lt;sharding:table-rule logic-table=&quot;t_order_item&quot; actual-data-nodes=&quot;dbtbl_${0..1}.t_order_item_${0..3}&quot; database-strategy-ref=&quot;databaseStrategy&quot; table-strategy-ref=&quot;tableStrategy&quot; /&gt;
            &lt;/sharding:table-rules&gt;
            &lt;sharding:binding-table-rules&gt;
                &lt;sharding:binding-table-rule logic-tables=&quot;t_order, t_order_item&quot; /&gt;
            &lt;/sharding:binding-table-rules&gt;
        &lt;/sharding:sharding-rule&gt;
        &lt;sharding:props&gt;
            &lt;prop key=&quot;sql.show&quot;&gt;true&lt;/prop&gt;
        &lt;/sharding:props&gt;
    &lt;/sharding:data-source&gt;
    
    &lt;reg:zookeeper id=&quot;regCenter&quot; server-lists=&quot;localhost:2181&quot; namespace=&quot;orchestration-spring-namespace&quot; base-sleep-time-milliseconds=&quot;1000&quot; max-sleep-time-milliseconds=&quot;3000&quot; max-retries=&quot;3&quot; /&gt;
&lt;/beans&gt;
</code></pre>

<h3 id="the-introduction-for-labels-in-zookeeper">The introduction for labels in Zookeeper</h3>

<h4 id="reg-zookeeper">&lt;reg:zookeeper/&gt;</h4>

<table>
<thead>
<tr>
<th>Name</th>
<th align="left">Type</th>
<th align="left">Required</th>
<th align="left">Default</th>
<th align="left">Info</th>
</tr>
</thead>

<tbody>
<tr>
<td>id</td>
<td align="left">String</td>
<td align="left">Y</td>
<td align="left"></td>
<td align="left">The primary key of registry in Spring.</td>
</tr>

<tr>
<td>server-lists</td>
<td align="left">String</td>
<td align="left">Y</td>
<td align="left"></td>
<td align="left">The server list to connect to Zookeeper<br />Including IP and port<br />multiple servers separated by commas<br />e.g. host1:2181,host2:2181</td>
</tr>

<tr>
<td>namespace</td>
<td align="left">String</td>
<td align="left">Y</td>
<td align="left"></td>
<td align="left">The namespace inf Zookeeper.</td>
</tr>

<tr>
<td>base-sleep-time-milliseconds</td>
<td align="left">int</td>
<td align="left">N</td>
<td align="left">1000</td>
<td align="left">The initial value of the interval for retry, unit: Millisecond.</td>
</tr>

<tr>
<td>max-sleep-time-milliseconds</td>
<td align="left">int</td>
<td align="left">N</td>
<td align="left">3000</td>
<td align="left">The max value of the interval for retry, unit: Millisecond.</td>
</tr>

<tr>
<td>max-retries</td>
<td align="left">int</td>
<td align="left">N</td>
<td align="left">3</td>
<td align="left">The number of retry.</td>
</tr>

<tr>
<td>session-timeout-milliseconds</td>
<td align="left">int</td>
<td align="left">N</td>
<td align="left">60000</td>
<td align="left">Session timeout, unit: Millisecond.</td>
</tr>

<tr>
<td>connection-timeout-milliseconds</td>
<td align="left">int</td>
<td align="left">N</td>
<td align="left">15000</td>
<td align="left">Connection timeout, unit: Millisecond.</td>
</tr>

<tr>
<td>digest</td>
<td align="left">String</td>
<td align="left">N</td>
<td align="left"></td>
<td align="left">The permission token to connect to Zookeeper, and the default is no permission validation.</td>
</tr>
</tbody>
</table>

<h3 id="the-config-example-in-etcd">The config example in Etcd</h3>

<pre><code class="language-xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
    xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
    xmlns:sharding=&quot;http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding&quot;
    xmlns:reg=&quot;http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg&quot;
    xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/context 
                        http://www.springframework.org/schema/context/spring-context.xsd 
                        http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding 
                        http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding/sharding.xsd 
                        http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg 
                        http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg/reg.xsd
                        &quot;&gt;
    &lt;context:property-placeholder location=&quot;classpath:conf/rdb/conf.properties&quot; ignore-unresolvable=&quot;true&quot; /&gt;
    
    &lt;bean id=&quot;dbtbl_0&quot; class=&quot;org.apache.commons.dbcp.BasicDataSource&quot; destroy-method=&quot;close&quot;&gt;
        &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot; /&gt;
        &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost:3306/dbtbl_0&quot; /&gt;
        &lt;property name=&quot;username&quot; value=&quot;root&quot; /&gt;
        &lt;property name=&quot;password&quot; value=&quot;&quot; /&gt;
    &lt;/bean&gt;
    
    &lt;bean id=&quot;dbtbl_1&quot; class=&quot;org.apache.commons.dbcp.BasicDataSource&quot; destroy-method=&quot;close&quot;&gt;
        &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot; /&gt;
        &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost:3306/dbtbl_1&quot; /&gt;
        &lt;property name=&quot;username&quot; value=&quot;root&quot; /&gt;
        &lt;property name=&quot;password&quot; value=&quot;&quot; /&gt;
    &lt;/bean&gt;
    
    &lt;sharding:standard-strategy id=&quot;databaseStrategy&quot; sharding-column=&quot;user_id&quot; precise-algorithm-class=&quot;io.shardingjdbc.spring.algorithm.PreciseModuloDatabaseShardingAlgorithm&quot; /&gt;
    &lt;sharding:standard-strategy id=&quot;tableStrategy&quot; sharding-column=&quot;order_id&quot; precise-algorithm-class=&quot;io.shardingjdbc.spring.algorithm.PreciseModuloTableShardingAlgorithm&quot; /&gt;
    
    &lt;sharding:data-source id=&quot;shardingDataSource&quot; registry-center-ref=&quot;regCenter&quot;&gt;
        &lt;sharding:sharding-rule data-source-names=&quot;dbtbl_0,dbtbl_1&quot; default-data-source-name=&quot;dbtbl_0&quot;&gt;
            &lt;sharding:table-rules&gt;
                &lt;sharding:table-rule logic-table=&quot;t_order&quot; actual-data-nodes=&quot;dbtbl_${0..1}.t_order_${0..3}&quot; database-strategy-ref=&quot;databaseStrategy&quot; table-strategy-ref=&quot;tableStrategy&quot; /&gt;
                &lt;sharding:table-rule logic-table=&quot;t_order_item&quot; actual-data-nodes=&quot;dbtbl_${0..1}.t_order_item_${0..3}&quot; database-strategy-ref=&quot;databaseStrategy&quot; table-strategy-ref=&quot;tableStrategy&quot; /&gt;
            &lt;/sharding:table-rules&gt;
            &lt;sharding:binding-table-rules&gt;
                &lt;sharding:binding-table-rule logic-tables=&quot;t_order, t_order_item&quot; /&gt;
            &lt;/sharding:binding-table-rules&gt;
        &lt;/sharding:sharding-rule&gt;
        &lt;sharding:props&gt;
            &lt;prop key=&quot;sql.show&quot;&gt;true&lt;/prop&gt;
        &lt;/sharding:props&gt;
    &lt;/sharding:data-source&gt;
    
    &lt;reg:etcd id=&quot;regCenter&quot; server-lists=&quot;http://localhost:2379&quot; time-to-live-seconds=&quot;60&quot; timeout-milliseconds=&quot;500&quot; max-retries=&quot;3&quot; retry-interval-milliseconds=&quot;200&quot;/&gt;
&lt;/beans&gt;
</code></pre>

<h3 id="the-introduction-for-labels-in-etcd">The introduction for labels in Etcd</h3>

<h4 id="reg-etcd">&lt;reg:etcd/&gt;</h4>

<table>
<thead>
<tr>
<th>Name</th>
<th align="left">Type</th>
<th align="left">Required</th>
<th align="left">Default</th>
<th align="left">Info</th>
</tr>
</thead>

<tbody>
<tr>
<td>id</td>
<td align="left">String</td>
<td align="left">Y</td>
<td align="left"></td>
<td align="left">The primary key of registry in Spring.</td>
</tr>

<tr>
<td>server-lists</td>
<td align="left">String</td>
<td align="left">Y</td>
<td align="left"></td>
<td align="left">The server list to connect to Etcd<br />Including IP and port<br />multiple servers separated by commas<br />e.g. <a href="http://host1:2379,http://host2:2379">http://host1:2379,http://host2:2379</a></td>
</tr>

<tr>
<td>time-to-live-seconds</td>
<td align="left">int</td>
<td align="left">N</td>
<td align="left">60</td>
<td align="left">The survival time of temporary nodes <br /> Unit: Second.</td>
</tr>

<tr>
<td>timeout-milliseconds</td>
<td align="left">int</td>
<td align="left">N</td>
<td align="left">500</td>
<td align="left">Session timeout, unit: Millisecond.</td>
</tr>

<tr>
<td>max-retries</td>
<td align="left">int</td>
<td align="left">N</td>
<td align="left">3</td>
<td align="left">The number of retry.</td>
</tr>

<tr>
<td>retry-interval-milliseconds</td>
<td align="left">int</td>
<td align="left">N</td>
<td align="left">200</td>
<td align="left">The interval of retry<br />Unit: Millisecond.</td>
</tr>
</tbody>
</table>

<h2 id="4-the-spring-boot-configuration">4. The Spring Boot Configuration</h2>

<h3 id="import-the-dependency-of-maven-3">Import the dependency of maven</h3>

<pre><code class="language-xml">&lt;dependency&gt;
    &lt;groupId&gt;io.shardingjdbc&lt;/groupId&gt;
    &lt;artifactId&gt;sharding-jdbc-orchestration-spring-boot-starter&lt;/artifactId&gt;
    &lt;version&gt;${latest.release.version}&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>

<h3 id="the-configuration-example-in-zookeeper-1">The configuration example in Zookeeper</h3>

<h4 id="the-introduction-for-orchestration-configs-of-sharding-in-spring-boot">The introduction for orchestration configs of Sharding in Spring Boot</h4>

<pre><code class="language-yaml">sharding.jdbc.datasource.names=ds,ds_0,ds_1
sharding.jdbc.datasource.ds.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds.driverClassName=org.h2.Driver
sharding.jdbc.datasource.ds.url=jdbc:mysql://localhost:3306/ds
sharding.jdbc.datasource.ds.username=root
sharding.jdbc.datasource.ds.password=

sharding.jdbc.datasource.ds_0.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds_0.driverClassName=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_0.url=jdbc:mysql://localhost:3306/ds_0
sharding.jdbc.datasource.ds_0.username=root
sharding.jdbc.datasource.ds_0.password=

sharding.jdbc.datasource.ds_1.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds_1.driverClassName=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_1.url=jdbc:mysql://localhost:3306/ds_1
sharding.jdbc.datasource.ds_1.username=root
sharding.jdbc.datasource.ds_1.password=

sharding.jdbc.config.sharding.default-data-source-name=ds
sharding.jdbc.config.sharding.default-database-strategy.inline.sharding-column=user_id
sharding.jdbc.config.sharding.default-database-strategy.inline.algorithm-inline-expression=ds_${user_id % 2}
sharding.jdbc.config.sharding.tables.t_order.actualDataNodes=ds_${0..1}.t_order_${0..1}
sharding.jdbc.config.sharding.tables.t_order.tableStrategy.inline.shardingColumn=order_id
sharding.jdbc.config.sharding.tables.t_order.tableStrategy.inline.algorithmInlineExpression=t_order_${order_id % 2}
sharding.jdbc.config.sharding.tables.t_order.keyGeneratorColumnName=order_id
sharding.jdbc.config.sharding.tables.t_order_item.actualDataNodes=ds_${0..1}.t_order_item_${0..1}
sharding.jdbc.config.sharding.tables.t_order_item.tableStrategy.inline.shardingColumn=order_id
sharding.jdbc.config.sharding.tables.t_order_item.tableStrategy.inline.algorithmInlineExpression=t_order_item_${order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.keyGeneratorColumnName=order_item_id

sharding.jdbc.config.orchestration.name=demo_spring_boot_ds_sharding
sharding.jdbc.config.orchestration.overwrite=true
sharding.jdbc.config.orchestration.zookeeper.namespace=orchestration-spring-boot-sharding-test
sharding.jdbc.config.orchestration.zookeeper.server-lists=localhost:2181
</code></pre>

<h3 id="the-configuration-example-in-etcd">The configuration example in Etcd</h3>

<h4 id="the-introduction-for-orchestration-configs-of-read-write-splitting-in-spring-boot">The introduction for orchestration configs of Read-write splitting in Spring Boot</h4>

<pre><code class="language-yaml">sharding.jdbc.datasource.names=ds,ds_0,ds_1
sharding.jdbc.datasource.ds.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds.driverClassName=org.h2.Driver
sharding.jdbc.datasource.ds.url=jdbc:mysql://localhost:3306/ds
sharding.jdbc.datasource.ds.username=root
sharding.jdbc.datasource.ds.password=

sharding.jdbc.datasource.ds_0.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds_0.driverClassName=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_0.url=jdbc:mysql://localhost:3306/ds_0
sharding.jdbc.datasource.ds_0.username=root
sharding.jdbc.datasource.ds_0.password=

sharding.jdbc.datasource.ds_1.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds_1.driverClassName=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_1.url=jdbc:mysql://localhost:3306/ds_1
sharding.jdbc.datasource.ds_1.username=root
sharding.jdbc.datasource.ds_1.password=

sharding.jdbc.config.sharding.default-data-source-name=ds
sharding.jdbc.config.sharding.default-database-strategy.inline.sharding-column=user_id
sharding.jdbc.config.sharding.default-database-strategy.inline.algorithm-inline-expression=ds_${user_id % 2}
sharding.jdbc.config.sharding.tables.t_order.actualDataNodes=ds_${0..1}.t_order_${0..1}
sharding.jdbc.config.sharding.tables.t_order.tableStrategy.inline.shardingColumn=order_id
sharding.jdbc.config.sharding.tables.t_order.tableStrategy.inline.algorithmInlineExpression=t_order_${order_id % 2}
sharding.jdbc.config.sharding.tables.t_order.keyGeneratorColumnName=order_id
sharding.jdbc.config.sharding.tables.t_order_item.actualDataNodes=ds_${0..1}.t_order_item_${0..1}
sharding.jdbc.config.sharding.tables.t_order_item.tableStrategy.inline.shardingColumn=order_id
sharding.jdbc.config.sharding.tables.t_order_item.tableStrategy.inline.algorithmInlineExpression=t_order_item_${order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.keyGeneratorColumnName=order_item_id

sharding.jdbc.config.orchestration.name=demo_spring_boot_ds_sharding
sharding.jdbc.config.orchestration.overwrite=true
sharding.jdbc.config.orchestration.etcd.server-lists=localhost:2379
</code></pre>

<h4 id="the-introduction-for-orchestration-configs-of-sharding-in-spring-boot-1">The introduction for orchestration configs of Sharding in Spring Boot</h4>

<p>Refer to The introduction for orchestration configs of Sharding in YAML.</p>


      
      
      </div>
    </div>

    

    <div id="navigation">
        
        <a class="nav nav-prev" href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/configuration/"> <i class="fa fa-chevron-left"></i></a>
        <a class="nav nav-next" href="http://shardingjdbc.io/document/legacy/2.x/en/02-guide/hint-sharding-value/" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>
    </div>

    </section>
    <div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
      <div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
    </div>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/clipboard.min.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/perfect-scrollbar.min.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/perfect-scrollbar.jquery.min.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/jquery.sticky-kit.min.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/featherlight.min.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/html5shiv-printshiv.min.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/highlight.pack.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/learn.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/hugo-learn.js"></script>
    <script src="http://cdn.bootcss.com/highlight.js/9.8.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

  </body>
</html>

